package com.film.dao.impl;

import java.util.List;

import org.springframework.jdbc.core.JdbcTemplate;

import com.film.dao.FilmTypeDao;
import com.film.domain.FilmType;
import com.film.rowMapper.FilmAndTypeRowMapper;
import com.film.rowMapper.FilmTypeRowMapper;
import com.film.util.DBUtil;

public class FilmTypeDaoImpl implements FilmTypeDao {
	private JdbcTemplate temp = new JdbcTemplate(DBUtil.getDataScorse());
	@Override
	public List<FilmType> selectFilmType(int film_id) {
		String sql = "select * from filmtype t1,film_type t2 where t1.type_id = t2.type_id and t2.film_id = ?";
		return temp.query(sql, new FilmTypeRowMapper(),film_id);
	}
	@Override
	public List<FilmType> selectType() {
		String sql = "select * from filmtype";
		return temp.query(sql,new FilmTypeRowMapper());
	}
	@Override
	public int addFilmType(int filmId, int typeId) {
		String sql ="insert into film_type values(default,?,?)";
		return temp.update(sql,filmId,typeId);
	}
	@Override
	public List<FilmType> limitFilmType(int pageNum, int stripNum) {
		String sql = "select * from filmtype limit ?,?";
		return temp.query(sql, new FilmTypeRowMapper(),pageNum,stripNum);
	}
	@Override
	public int deleteFilmType(int typeId) {
		String sql = "delete from filmtype where type_id = ?";
		return temp.update(sql,typeId);
	}
	@Override
	public List<Integer> selectFilmTypeAndFilmMiddleSurface(int typeId) {
		String sql = "select DISTINCT type_id  from film_type where type_id = ?";
		return temp.query(sql, new FilmAndTypeRowMapper(),typeId);
	}
	@Override
	public int addTypeName(String typeName) {
		String sql ="insert into filmtype values(default,?)";
		return temp.update(sql,typeName);
	}

}
